﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BuyLocalBonds;

namespace BuyLocalBonds
{
    public partial class searchBond : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Queries the database for the bond details of the specified cusip
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearchBond_Click(object sender, EventArgs e)
        {
            SqlBean sb = new SqlBean();

            double Coupon_Low;
            if (CouponLow.Text.Length == 0)
            {
                Coupon_Low = 0;
            }
            else
            {
                Coupon_Low = Convert.ToDouble(CouponLow.Text);
            }

            double Coupon_High;
            if (CouponHigh.Text.Length == 0)
            {
                Coupon_High = 0;
            }
            else
            {
                Coupon_High = Convert.ToDouble(CouponHigh.Text);
            }

            double Current_Low;
            if (CurrentLow.Text == "")
            {
                Current_Low = 0;
            }
            else
            {
                Current_Low = Convert.ToDouble(CurrentLow.Text);
            }

            double Current_High;
            if (CurrentHigh.Text == "")
            {
                Current_High = 0;
            }
            else
            {
                Current_High = Convert.ToDouble(CurrentHigh.Text);
            }

            double Par_Low;
            if (ParLow.Text == "")
            {
                Par_Low = 0;
            }
            else
            {
                Par_Low = Convert.ToDouble(ParLow.Text);
            }

            double Par_High;
            if (ParHigh.Text == "")
            {
                Par_High = 0;
            }
            else
            {
                Par_High = Convert.ToDouble(ParHigh.Text);
            }

            double YTM_Low;
            if (YTMlow.Text == "")
            {
                YTM_Low = 0;
            }
            else
            {
                YTM_Low = Convert.ToDouble(YTMlow.Text);
            }

            double YTM_High;
            if (YTMhigh.Text == "")
            {
                YTM_High = 0;
            }
            else
            {
                YTM_High = Convert.ToDouble(YTMhigh.Text);
            }

            double Px_Low;
            if (PriceLow.Text == "")
            {
                Px_Low = 0;
            }
            else
            {
                Px_Low = Convert.ToDouble(PriceLow.Text);
            }

            double Px_High;
            if (PriceHigh.Text == "")
            {
                Px_High = 0;
            }
            else
            {
                Px_High = Convert.ToDouble(PriceHigh.Text);
            }

            DataSet ds = sb.SearchBondsForPurchase(bondName.Text, cusip.Text, issuer.Text, Coupon_Low, Coupon_High, Current_Low, Current_High, Par_Low, Par_High, YTM_Low, YTM_High, Px_Low, Px_High);
            //RatingLow.Text, RatingHigh.Text, 
            //, Convert.ToDouble(MaturityLow.Text), Convert.ToDouble(MaturityHigh.Text)

            //SearchResultGrid.DataSource = ds.Tables[0];
            //SearchResultGrid.DataBind();

            Session["resultDataSet"] = ds;
            Response.Redirect("SearchResults.aspx");
        }

        protected void CouponLow_TextChanged(object sender, EventArgs e)
        {

        }
    }
}